package clientServlets;

import java.io.IOException;
import java.util.logging.Logger;

import javax.servlet.ServletException;
import javax.servlet.http.*;

import businessServlets.LogOutBusiness;

import sessionMenegment.SessionMgr;

@SuppressWarnings("serial")
public class LogOutClient extends HttpServlet {
	private static final Logger log = Logger.getLogger(LogOutClient.class.getName());

	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		
		SessionMgr sessionMgr = SessionMgr.getInst();
		sessionMgr.logOutUser(req.getSession(), resp, req,(String) req.getSession().getAttribute("userNameClient"));
		req.getSession().removeAttribute("userNameClient");
		
		sessionMgr.logOutUser(req.getSession(), resp, req,(String) req.getSession().getAttribute("userNameBusiness"));
		req.getSession().removeAttribute("userNameBusiness");
		
		resp.sendRedirect("/home.jsp");
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String redirect = "home.jsp";
		
		SessionMgr sessionMgr = SessionMgr.getInst();
		redirect = sessionMgr.logOutUser(req.getSession(), resp, req,(String) req.getSession().getAttribute("userNameClient"));
		req.getSession().removeAttribute("userNameClient");
		
		sessionMgr.logOutUser(req.getSession(), resp, req,(String) req.getSession().getAttribute("userNameBusiness"));
		req.getSession().removeAttribute("userNameBusiness");
		
		System.out.println("Result is: "+redirect);
		log.warning(redirect);
		Logger.getLogger("LogOutClient").warning("Result is: "+redirect);
		resp.sendRedirect(redirect);

	}
	
}
